﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Telerik.Web.UI;

namespace Sistema_de_Taller.SDT_UI.Vehicle
{
    public partial class vehicle_details : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public static UInt32 VehicleID;

        private void Page_Init(object sender, System.EventArgs e)
        {
            VehicleID = Convert.ToUInt32(Request.QueryString["Id"]);
            loadForm(VehicleID);
        }

        private void loadForm(UInt32 VehicleID)
        {
            DataSet Vehicle;

            SDT_DAL.Utilities.Vehicle_DAL VehicleData = new SDT_DAL.Utilities.Vehicle_DAL();

            Vehicle = VehicleData.VehicleDataIdLoad(VehicleID);
 
            //Cargo datos Repuestos
            txtBrand.Text = Vehicle.Tables[0].Rows[0].ItemArray[1].ToString().Trim();
            txtModel.Text = Vehicle.Tables[0].Rows[0].ItemArray[2].ToString().Trim();
            txtPatent.Text = Vehicle.Tables[0].Rows[0].ItemArray[3].ToString().Trim();
            txtEngineNumber.Text = Vehicle.Tables[0].Rows[0].ItemArray[4].ToString().Trim();
            txtSerialNumber.Text = Vehicle.Tables[0].Rows[0].ItemArray[5].ToString().Trim();
            dpSellDate.SelectedDate = Convert.ToDateTime(Vehicle.Tables[0].Rows[0].ItemArray[6]);

        }

        protected void dpSellDate_Load(object sender, EventArgs e)
        {
            dpSellDate.SelectedDate = DateTime.Today;
        }

        protected void btnUpdateVehicle_Click(object sender, EventArgs e)
        {
            MessageOk.Visible = false;
            Common_Files.Definitions.Vehicle Vehicle = new Common_Files.Definitions.Vehicle();

            Vehicle.Vehicle_ID = VehicleID;
            Vehicle.Vehicle_Brand = txtBrand.Text;
            Vehicle.Vehicle_Model = txtModel.Text;
            Vehicle.Vehicle_Patent = txtPatent.Text;
            Vehicle.Vehicle_EngineNumber = txtEngineNumber.Text;
            Vehicle.Vehicle_SerialNumber = Convert.ToUInt32(txtSerialNumber.Text);
            Vehicle.Vehicle_SellDate = dpSellDate.SelectedDate.Value;
            SDT_DAL.Utilities.Vehicle_DAL vehicleDAL = new SDT_DAL.Utilities.Vehicle_DAL();

            vehicleDAL.VehicleUpdate(Vehicle);

            lblMessages.Text = "Vehiculo modificado satisfactoriamente";
            MessageOk.Visible = true;
        }


    }
}